<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/22
 * Time: 16:55
 */

namespace Home\Controller;
use Think\Controller;
class CostController extends Controller {
    public function index(){
        $user=M('Cost');
        $result=$user->sum("money");
        $this->assign('sum',$result."元");

        $news =M();//通过系统自带的M方法创建表的对象
        $count=$news->count();//获取表中数据的记录总数
        $page=new \Think\Page($count,2);
        $page->setConfig('header','<li class="rows">共<b>%TOTAL_ROW%</b>条记录 第
                    <b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</li>');
        $page->setConfig('prev','上一页');
        $page->setConfig('next','下一页');
        $page->setConfig('end','末页');
        $page->setConfig('first','首页');
        $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        $page->lastSuffix=false;//设置最后一页不显示为总页数
        $show=$page->show();
        $sql="select * from tp_price LIMIT ".$page->firstRow.','.$page->listRows;
        $news_list=$news->query($sql);
//        $news_list=$news->field($sql)
//            ->limit($page->firstRow.','.$page->listRows)
//            ->select();
//        $news_list=$this->filter($news_list);
//        echo $news->getLastSql();
//       var_dump($news_list);
//        exit();
        $this->assign('news_list',$news_list);
        $this->display();
    }
}